package kafeisc.web.servlet.manager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Classname ${NAME}
 * @Description TODO
 * @Date 2020/5/13 0:42
 * @Created 
 */
@WebServlet(name = "LogoutManagerServlet")
public class LogoutManagerServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取session对象.
        HttpSession session = request.getSession();
        // 销毁session
        session.invalidate();
        // flag标识
        String flag = request.getParameter("flag");
        if (flag == null || flag.trim().isEmpty()) {
            // 重定向到首页
            response.getWriter().println("<script>parent.window.location.href=\""+ request.getContextPath() +"/admin/login/login.jsp\"</script>");
        }
    }
}
